package com.ruoyi.web.controller.enforce;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.enforce.domain.EnforceOrgManage;
import com.ruoyi.enforce.service.IEnforceOrgManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 项目实施策划的组织机构管理Controller
 *
 * @author ruoyi
 * @date 2021-11-30
 */
@Api(tags = "项目实施策划组织管理")
@RestController
@Validated
@RequestMapping("/enforce/manage")
public class EnforceOrgManageController extends BaseController {
    @Autowired
    private IEnforceOrgManageService enforceOrgManageService;

    /**
     * 查询项目实施策划的组织机构管理列表
     */
    @ApiOperation("项目分工列表")
    @PreAuthorize("@ss.hasPermi('system:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(EnforceOrgManage enforceOrgManage) {
        startPage();
        List<EnforceOrgManage> list = enforceOrgManageService.selectEnforceOrgManageList(enforceOrgManage);
        return getDataTable(list);
    }

    /**
     * 导出项目实施策划的组织机构管理列表
     */
    @ApiOperation("分工列表导出")
    @PreAuthorize("@ss.hasPermi('system:manage:export')")
    @Log(title = "项目实施策划的组织机构管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EnforceOrgManage enforceOrgManage) {
        List<EnforceOrgManage> list = enforceOrgManageService.selectEnforceOrgManageList(enforceOrgManage);
        ExcelUtil<EnforceOrgManage> util = new ExcelUtil<EnforceOrgManage>(EnforceOrgManage.class);
        return util.exportExcel(list, "项目实施策划的组织机构管理数据");
    }

    /**
     * 获取项目实施策划的组织机构管理详细信息
     */
    @ApiOperation("根据id获取项目分工")
    @PreAuthorize("@ss.hasPermi('system:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(enforceOrgManageService.selectEnforceOrgManageById(id));
    }

    /**
     * 新增项目实施策划的组织机构管理
     */
    @ApiOperation("添加项目分工")
    @PreAuthorize("@ss.hasPermi('system:manage:add')")
    @Log(title = "项目实施策划的组织机构管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnforceOrgManage enforceOrgManage) {
        enforceOrgManage.setCreateBy(getUsername());
        return toAjax(enforceOrgManageService.insertEnforceOrgManage(enforceOrgManage));
    }

    /**
     * 修改项目实施策划的组织机构管理
     */
    @ApiOperation("编辑项目分工")
    @PreAuthorize("@ss.hasPermi('system:manage:edit')")
    @Log(title = "项目实施策划的组织机构管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnforceOrgManage enforceOrgManage) {
        return toAjax(enforceOrgManageService.updateEnforceOrgManage(enforceOrgManage));
    }

    /**
     * 删除项目实施策划的组织机构管理
     */
    @ApiOperation("删除项目分工")
    @PreAuthorize("@ss.hasPermi('system:manage:remove')")
    @Log(title = "项目实施策划的组织机构管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(enforceOrgManageService.deleteEnforceOrgManageByIds(ids));
    }


    /*    经理看日程报 */
    @ApiOperation("日程看报信息")
    @GetMapping("/scheduleShow")
    public AjaxResult scheduleShow() {
        return AjaxResult.success();
    }

    /*标记重要事项 标记完成情况*/
    @ApiOperation("日程标注主要事项")
    @PostMapping("/markMajor")
    public AjaxResult markMajor(@NotNull(message = "id不能为空") Long id, Boolean isMajor) {
        EnforceOrgManage enforceOrgManage = enforceOrgManageService.selectEnforceOrgManageById(id);
        enforceOrgManage.setMajor(isMajor);
        return toAjax(enforceOrgManageService.updateEnforceOrgManage(enforceOrgManage));
    }

    @ApiOperation("日程标注完成情况")
    @PostMapping("/markCompleted")
    public AjaxResult markCompleted(@NotNull(message = "id不能为空") Long id, Boolean isCompleted) {
        EnforceOrgManage enforceOrgManage = enforceOrgManageService.selectEnforceOrgManageById(id);
        enforceOrgManage.setCompleted(isCompleted);
        return toAjax(enforceOrgManageService.updateEnforceOrgManage(enforceOrgManage));
    }

}
